<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core\lang;
use classlib\core as C;
use classlib\core\controller;
class Cpayconfig extends controller {

	public function main() {
		$view   = C\view::inst('extjs');
		$userid = Cadmin::chkaccess($view);
		$dlang  = lang::inst('dd');
		$view->assign('usetype', $dlang->get('sh0009'));
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('live/finance/payconfig.ext.js');
	}
	
	public function dosave() {
		$view  = C\view::inst('json');
		Cadmin::chkaccess($view);
		$id    = (int)input::post('id');
		$data  = array();
		$data['coin']    = (int)input::post('coin');
		$data['money']   = input::post('money');
		$data['money']   = $data['money'] * 100;
		$data['usetype'] = (int)input::post('usetype');
		$data['app']     = input::post('app');
		$data['stime']   = C\config::$nowtime;
		if ($id > 0) {
			C\model::load('pro.inc.payconfig')->save($id, $data);
		} else {
			C\model::load('pro.inc.payconfig')->new_one($data);
		}
		$view->display();
	}
	
	public function dolist() {
		$view   = C\view::inst('json');
		Cadmin::chkaccess($view);
		list($start, $limit, $sort) = Cadmin::offset();
		$orm    = C\model::load('pro.inc.payconfig');
		$total  = $orm->get_total($where);
		$list   = array();
		if ($total) {
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			foreach ($list as &$item) {
				$item['money'] = $item['money']/100;
				$item['stime'] = date('Y-m-d H:i:s', $item['stime']);
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}